package bitmap
{
	import com.greensock.TweenLite;
	import com.greensock.easing.Linear;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	[SWF(width="600",height="600",backgroundColor="#bdb8b8")]
	public class BitmapAnimate extends Sprite
	{
		[Embed(source="assets/progress.png")]
		private var pic:Class;
		
		private var bmp:Bitmap;
		private var bmpd:BitmapData;
		
		private var sbmpd:BitmapData;
		
		private const frames:int = 6;
		
		private var timer:Timer;
		
		private var lastTime:int;
		
		public function BitmapAnimate()
		{
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.stage.align = StageAlign.TOP_LEFT;
			init();
		}
		
		public function init():void {
			var request:URLRequest = new URLRequest("progress.png");
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
			loader.load(request);
		}
		
		public function loadComplete(event:Event):void {
			var loaderInfo:LoaderInfo = event.target as LoaderInfo;
			sbmpd = new BitmapData(loaderInfo.width,loaderInfo.height,true,0x00ffffff);
			sbmpd.draw(loaderInfo.content);
			bmpd = new BitmapData(sbmpd.width/frames,sbmpd.height);
			bmpd.copyPixels(sbmpd,new Rectangle(0,0,sbmpd.width/frames,sbmpd.height),new Point(0,0));
			bmp = new Bitmap();
			bmp.bitmapData = bmpd;
			this.addChild(bmp);
			bmp.x = 200;
			bmp.y = 200;
			
			var timer:Timer = new Timer(100);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
			timer.start();
		}
		
		private var i:int = 0;//行
		private var j:int = 0;//列
		private var angle:Number = 0;
		public function onTimer(event:TimerEvent=null):void {
				bmpd.copyPixels(sbmpd,new Rectangle(j*sbmpd.width/frames,0,sbmpd.width/frames,sbmpd.height),new Point(0,0));
				this.bmp.bitmapData = bmpd;
				j++;
				if(j==frames) j=0;
		}
	}
}